<?php
require ('../include/init.inc.php');
$method = $module_id = '';
Template::assign ( 'content_header', $menu );
extract ( $_GET );
if (! empty ( $id ) && $method=='del') {
	$result = Card::delete ( $id );	
}
if ($method == 'export') {
	$modules = Card::getList($card_no,$open_phone,$start_time,$end_time);

	set_time_limit(0);  
	ini_set('memory_limit', '512M');  
	  
	//为fputcsv()函数打开文件句柄  
	$output = fopen('php://output', 'w') or die("can't open php://output");  
	//告诉浏览器这个是一个csv文件  
	$filename = "卡信息" . date('Y-m-d', time());  
	header("Content-Type: application/force-download");  
	header("Content-type:text/csv;charset=gbk");  
	header("Content-Disposition: attachment; filename=$filename.csv");  
	//输出表头  
	$table_head = array('id','Sim Card','Supplier','Type', 'Valid Date','Used Date', 'Phone No.', 'Guest Phone No.','Channel');  
	for ($i=0; $i < count($table_head); $i++) { 
		$table_head[$i] = iconv('utf-8','gbk', $table_head[$i]);
	}
	fputcsv($output, $table_head);  
	//输出每一行数据到文件中  
	foreach ($modules as $e) {  
	//    unset($e['xx']);//若有多余字段可以使用unset去掉  
	//    $e['xx'] = isset($e['xxx']) ? "xx" : 'x'; //可以根据需要做相应处理  
	    //输出内容  
	    $table_head = array_values($e);
	    for ($i=0; $i < count($table_head); $i++) { 
			$table_head[$i] = iconv('utf-8','gbk', $table_head[$i]);
		}
	    fputcsv($output, $table_head);  
	}  
	fclose($output) or die("can't close php://output");  
	exit;  
}

$modules = Card::getList($card_no,$open_phone,$start_time,$end_time);
$confirm_html = OSAdmin::renderJsConfirm("icon-remove");
Template::assign ( 'modules', $modules );
Template::assign ( '_GET', $_GET );
Template::assign ( 'osadmin_action_confirm' , $confirm_html);
Template::display ( 'panel/sms.tpl' );